<template>
  <div>
    
    <div class="bg" v-if="islogin">
      <div class="yuan"><img :src="userInfo.avatar" alt="" /></div>
      <span class="name">{{ userInfo.nickname }}</span>

      <van-button round type="primary" size="mini" route to="user_edit"
        >编辑资料</van-button
      >
    </div>
    <div class="dibu" v-if="islogin">
      <div class="left">
        <p>1</p>
        <p>头条</p>
      </div>
      <div class="right">
        <p>4</p>
        <p>获赞</p>
      </div>
    </div>

    <div class="dl" v-else>
      <router-link to="/login" class="aaa">登录</router-link>
    </div>

    <van-grid clickable :column-num="2">
      <van-grid-item icon="star-o" text="收藏" to="/" />
      <van-grid-item icon="underway-o" text="历史" url="/vant/mobile.html" />
    </van-grid>
    <van-cell title="修改密码" is-link />
    <van-cell title="联系我们" is-link />
    <van-cell title="关于我们" is-link />

    <van-button
      type="primary"
      size="large"
      color="#fff"
      @click="logout"
      v-if="islogin"
      >退出登录</van-button
    >

    <van-tabbar v-model="active" route>
      <van-tabbar-item icon="home-o" to="/">首页</van-tabbar-item>
      <van-tabbar-item icon="add-o" to="/publish">发表</van-tabbar-item>
      <van-tabbar-item icon="manager-o" to="/my">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { Skeleton } from "vant";
import { Grid, GridItem } from "vant";
import { mapState } from "vuex";
import { Dialog } from "vant";
export default {
  name: "my",
  data() {
    return {
      active: 2,
      token2:''
    };
  },
  computed: {
    ...mapState(["uid", "token", "userInfo", "islogin"]),
    // uid(){
    //   return this.$store.state.uid
    // }
  },

  // created() {

  //   let{uid,token,userInfo}=localStorage;

  //   if(uid){
  //     this.islogin=true
  //   }else{
  //     this.islogin=false
  //   }console.log(this.islogin);
  //   console.log(uid)
  // },
  components: {
    [Skeleton.name]: Skeleton,
    [Grid.name]: Grid,
    [GridItem.name]: GridItem,
    [Dialog.Component.name]: Dialog.Component,
  },
  mounted() {
    this.token2=localStorage.getItem("token")
    console.log(this.token2);
  },
  methods: {
    async logout() {
      let res = await Dialog.confirm({
        title: "标题",
        message: "你确认退出吗？",
      });
      if (res == "confirm") {
        localStorage.clear();
        this.$store.commit("clear");
      }
    },
  },
};
</script>

<style lang="less" scpoed>
.bg {
  background-color: #07c160;
  display: flex;
  width: 100%;
  height: 110px;
}
.dl {
  background-color: #07c160;
  display: flex;
  width: 100%;
  height: 110px;
}
.aaa {
  margin: 40px 170px;
}
.yuan {
  margin: 40px 20px;
  width: 60px;
  height: 60px;
  background-color: #fff;
  border-radius: 100px;
}
.bg span {
  width: 63px;
}
img {
  width: 60px;
  height: 60px;
  border-radius: 100px;
}
.name {
  margin: 60px 10px;
  height: 20px;
}
.van-button--mini {
  display: flex;
  top: 63px;
  right: -112px;
  height: 30px;
  background-color: rgb(238, 236, 236);
  color: rgb(100, 99, 99);
  width: 60px;
}

.dibu {
  width: 100%;
  background-color: #07c160;
  display: flex;

  text-align: center;
}
.left {
  width: 50%;
  float: left;
}
.right {
  width: 50%;
  float: right;
}
.van-button--large .van-button__text {
  color: red;
}
</style>